package homwork1102;


import dao.basedb;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class homework1102 extends HttpServlet {
    basedb mysql=new basedb();
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
        doPost(request,response);

    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
        //设置编码格式
        response.setHeader("content-type", "text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");


        //获取值 type：0是登录 1是注册
        String type= request.getParameter("type");
        String username= request.getParameter("username");
        String userpassword=request.getParameter("password");
        if(type.equals("0")){
            //定义传输文件的类型
            response.setContentType("homework1102/json");
            //向网页传出JSON文件
            response.getWriter().print(mysql.select(username,userpassword));

        }else if (type.equals("1")){
            //定义传输文件的类型
            response.setContentType("homework1102/json");
            //向网页传出JSON文件
            response.getWriter().print(mysql.add(username,userpassword));

        }
        System.out.print(username+"密码"+userpassword);
    }




}
